/**
 * Created by Administrator on 2018/10/15.
 */
export default {
  props:['nameSelect'],
  data(){
    return{
      loading: true,
      list: [],
      totalD:[],
      nameList: [],
      total: 0,
      channelCodeCode:'',
      showModal: {
        isShow: false
      },
      ids: '',
      channelCodeList:[],
      typeList:[//0审核中，1通过，2拒绝 ，3电核
        {
          id:0,
          name:'审核中'
        },
        {
          id:1,
          name:'通过'
        },
        {
          id:2,
          name:'拒绝'
        },
   /*     {
          id:3,
          name:'电核'
        }*/
      ],
      options: {
        disabledDate (date) {
          return date && date.valueOf() > Date.now() ;
        }
      },
    }
  },
  mounted(){
    this.tag.name = this.nameSelect;
    this.getList(this.url);
    if(this.nameListUrl){
      this.getNameList(this.nameListUrl);
    }
    this.$store.commit('changeTag', this.tag.path);
    this.$store.commit('openPage', this.tag);
  },
  methods:{
    getChannel(){
      this.$post('/bkchannel/list',{pageLimit:100})
        .then((res) => {
          if(res.code === 0){
            this.channelCodeList = res.data.pageListData;
            this.params.channelCode = this.channelCodeList[0].channelCode;
            this.channelName = this.channelCodeList[0].channelName;
            // console.log( this.channelCodeList,'channel')
          }else{
            // this.$Message.error(res.msg);
          }
        }, (err) => {
          this.loading = false;
          console.log(err);
        })
    },
    //删除
    delItem(url,item) {
      this.$post(url ,item)
        .then((res) => {
          if(res.code === 0){
            this.$Message.success(`删除成功！`);
            this.getList(this.url);
          }
        }, (err) => {
          console.log(err);
        })
    },
    //是否人工审核
    isReview(s){
      let text = '';
      switch (s) {
        case 0:
          text = '否';
          break;
        case 1:
          text = '是';
          break;
      }
      return text;
    },
    //审核状态
    getStatus(s){
      let texts = '';
      let color = '';
      switch (s) {
        case 0:
          texts = '审核中';
          color = '#f90';
          break;
        case 1:
          texts = '通过';
          color = '#19be6b';
          break;
        case 2:
          texts = '拒绝';
          color = '#ed4014';
          break;
        /*case 3:
          texts = '电核';
          color = '#2db7f5';
          break;*/
      }
      return {txt:texts,color:color};
    },
    getType(num,type) {
      let obj = {};
      if(type == 'lendingChannel'){
        obj = { //渠道
          1:"易宝",
          2:"合利宝",
          9:"财务销账"
        }
      }else if(type == 'loanStatus'){
        obj = { //放款状态
          "0": "待放款",
          "1": "待人工放款",
          "2": "放款中",
          "3": "放款成功",
          "4": "放款失败"
        }
      }else if(type == 'payStatus'){
        obj = { //还款状态
          "0": {name:"正常",color:'#515a6e'},
          "1": {name:"部分还款",color:'#ed4014'},
          "2": {name:"结清",color:'#19be6b'},
          "3": {name:"逾期",color:'#ed4014'},
          "4": {name:"还款中",color:'#f90'},
        }
      }
      for (let key in obj) {
        if (key == num) {
          return obj[key];
          break;
        }
      }
    },
    // 转化为元
    toYuan(money){
      if(money){
        return (money/100).toFixed(2)
      }else{
        return 0
      }

    },

    //开始时间
    startTime(e){
      this.params.beginTime = e;
    },
    //结束时间
    endTime(e){
      this.params.endTime = e;
    },
    getList (url,type='') { // 获取列表
      this.loading = true;
      for(let key in this.params){
        if(this.params[key] == undefined){
          delete this.params[key]
        }
      }
      this.channelCodeCode = this.params.channelCode;
      if(this.params.channelCode == '0'){
        this.params.channelCode = null;
        // delete this.params['channelCode']
      }
      // console.log('params',this.params)

      if(type === 'refresh'){
        this.params.pageCurrent = 1;
      }

      this.$post(url,this.params)
        .then((res) => {
          if(res.code === 0){
            this.loading = false;
            this.totalD = res.data;
            this.total = res.data.resultCount;
            let list = res.data.pageListData;
            if(url == '/bkcollection/list'){
              list.map((item) => {
                if(item.settleStatus == 1){
                  item._disabled = true
                }
                if(item.allotStatus == 1){
                  item._disabled = true
                }
              })
            }
            this.list = list;
            if(this.list[0].channelName){
              if(this.list[0].channelName == '全部'){
                this.list.shift()
              }
            }
            this.params.channelCode = this.channelCodeCode;

          }else{
            // this.$Message.error(res.msg);
          }
        }, (err) => {
          this.loading = false;
          console.log(err);
        })
    },
    getNameList (url) { // 获取名称列表
      this.loading = true;
      this.$post(url)
        .then((res) => {
          this.loading = false;
          this.nameList = res.data;
          console.log(res);
        }, (err) => {
          this.loading = false;
          console.log(err);
        })
    },
    toRate(rate){
      if(rate){
        return (rate*100).toFixed(2)+'%'
      }else{
        return '0.00%'
      }
    },
    editItem (url,type,item={}) { // 添加、编辑
      this.$store.commit('editItem', item);
      this.$router.push({ path: url, query: { type: type }})
    },
    deleteItem (url) { // 删除单项
      let ids = this.ids;
      this.$del(url,{
        ids: ids
      })
        .then((res) => {
          if(res.code === 200){
            this.$Message.success('删除成功！');
            this.getList(this.url);
            this.ids = '';
          }else{
            // this.$Message.error(res.msg);
          }
        }, (err) => {
          console.log(err);
          this.ids = '';
        })
    },
    deleteAll () { // 删除全部
      if(this.ids === ''){
        this.$Message.warning('当前未选中！');
        return false;
      }else{
        this.showModal.isShow = true;
      }
    },
    getLocalTime(time) {//时间戳转日期
      if(time){
        const date = new Date(time);
        const year = date.getFullYear()
        const month = date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1
        const day = date.getDate() < 10 ? '0'+date.getDate() : date.getDate()
        const hour = date.getHours() < 10 ? '0'+date.getHours() : date.getHours()
        const minute = date.getMinutes() < 10 ? '0'+date.getMinutes(): date.getMinutes()
        const second = date.getSeconds() < 10 ? '0'+date.getSeconds(): date.getSeconds()
        const t1 = [year, month, day].join('-')
        const t2 = [hour, minute, second].join(':')
        return `${t1} ${t2}`
      }else{
        return '—'
      }
  },
  getLocalDate(time) {//时间戳转日期
    if(time){
      const date = new Date(time);
      const year = date.getFullYear()
      const month = date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1
      const day = date.getDate() < 10 ? '0'+date.getDate() : date.getDate()
      const t1 = [year, month, day].join('-')
      return `${t1}`
    }else{
      return '—'
    }
 },

 resetValidate(name) {
  this.$refs[name].resetFields();
},

    allUp(){
      if(this.ids){
        console.log(this.ids,'allup')
        this.type = 'allup';
        this.showModal.isShow = true;
      }else{
        this.$Message.warning('请勾选所需分配订单')
      }
    },
}
}
